package com.commerce.img.tools;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.LruCache;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.Volley;
import com.commerce.img.R;

public class MyImgLoader {
    Context context;
    public MyImgLoader(Context context, NetworkImageView imageView, String url) {
        this.context = context;
        this.imageView = imageView;
        imgUrl = url;
    }
    NetworkImageView imageView ;
    String imgUrl;
    public void inBitmap() {
        //请求队列
        RequestQueue requestQueue = Volley.newRequestQueue(context.getApplicationContext());
        //缓存
        final LruCache<String, Bitmap> mImageCache = new LruCache<String, Bitmap>(
                20);
        //加载构造一个图像加载器
        ImageLoader mImageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache() {
            @Override
            public Bitmap getBitmap(String url) {
                return mImageCache.get(url);
            }

            @Override
            public void putBitmap(String url, Bitmap bitmap) {
                mImageCache.put(url,bitmap);
            }
        });
        //加载方式标记
        imageView.setTag("Url");
        //加载时图片
        imageView.setDefaultImageResId(R.drawable.loading);
        //加载视频图片
        imageView.setErrorImageResId(R.drawable.nbg);
        //加载图片
        imageView.setImageUrl(imgUrl,mImageLoader);
    }
}
